package com.woniu.controller.sportsHealth;

import com.alibaba.excel.EasyExcel;
import com.github.pagehelper.PageInfo;

import com.woniu.model.sportsHealth.model.dto.BloodPressureDto;
import com.woniu.model.sportsHealth.model.vo.BloodPressureVo;
import com.woniu.service.sportsHealth.IBloodPressureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 血压表 前端控制器
 * </p>
 *
 * @author Jet
 * @since 2023-10-23
 */
@RestController
@RequestMapping("/blood-pressure")
public class BloodPressureController {

    @Autowired
    IBloodPressureService iBloodPressureService;
    @PostMapping("/findAll")
    public ResponseEntity<PageInfo<BloodPressureDto>> findAll(@RequestBody Map<String,Object> param){
        Integer pageNum = (Integer) param.get("pageNum");
        Integer pageSize = (Integer) param.get("pageSize");
        PageInfo<BloodPressureDto> pageInfo = iBloodPressureService.findAll(param, pageNum, pageSize);
        return ResponseEntity.ok(pageInfo);
    }
    @GetMapping("/export")
    public void pressureExport(HttpServletResponse response)throws IOException {
        List<BloodPressureVo> list = iBloodPressureService.findAllExport();

        response.setContentType("application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        response.setHeader("content-disposition","attachment;filename=parking.xlsx");

        ServletOutputStream stream = response.getOutputStream();
        EasyExcel.write(stream, BloodPressureVo.class)
                .sheet("血压表")
                .doWrite(list);

    }
}
